import { getRepairSendGoodList } from '@/api/return-factory'
import { ref } from 'vue'

/**
 * 返厂单发货列表服务
 */
export default function () {
  const getSendGoodListLoading = ref(false)
  const sendGoodList = ref<Array<ReturnFactoryAPIResponse.SendedGoodListItem>>([])

  const getSendGoodList = async (repairId: string) => {
    try {
      getSendGoodListLoading.value = true
      const res = await getRepairSendGoodList(repairId)
      getSendGoodListLoading.value = false
      if (res.data.code === 20000) {
        sendGoodList.value = res.data.data.data
        return ''
      }

      return res.data.message
    } catch (error) {
      getSendGoodListLoading.value = false
      return '获取发货列表失败，请稍后重试'
    }
  }

  return {
    sendGoodList,
    getSendGoodListLoading,
    getSendGoodList,
  }
}
